package com.comp6231.frontend;

import com.comp6231.common.EntityInitiator;

import java.util.Hashtable;

/**
 * 
 * This is the DPIS front end system's main class This initialzes and activates
 * the CORBA interface for client requests and implements server method where
 * each method will prepare the UDP packet to be sent to the leader coordinator
 * 
 * @author sknarula (narula.sk@gmail.com)
 * @since November 2013
 * 
 * 
 */
public class FrontEndInitiator extends EntityInitiator {

	/**
	 * host name of the leader coordinator
	 */
	protected static String leaderHostName;

	/**
	 * port number of the leader coordinator
	 */
	protected static int leaderUDPPort;

	/**
	 * boolean - if the leader host name and post is set
	 */
	protected static boolean hasLeaderAddress = false;

	/**
	 * save the request sent to coordinator Integer - request id String -
	 * message sent
	 */
	protected static Hashtable<Integer, String> clientRequests = new Hashtable<Integer, String>();

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		/*
		 * Start the coordinator interface thread to enable receiving of UDP
		 * messages from Coordinator The Register leader will also call the open
		 * client interface function once the Leader coordinate register itself
		 */
		new Thread(new RegisterLeader(frontEnd_hostName,
				frontEnd_UDPPort_control)).start();
		System.out.println("Leader Registration System is running!");
	}

	public static int getLeaderUDPPort() {
		return leaderUDPPort;
	}

}
